package com.runen.infinitemovement.tool;

import android.content.Context;
import android.content.Intent;

import com.runen.infinitemovement.Constant;
import com.runen.infinitemovement.activity.DayTaskActivity;
import com.runen.infinitemovement.activity.InviteFriendsActivity;
import com.runen.infinitemovement.activity.MainActivity;
import com.runen.infinitemovement.activity.MyActivity;
import com.runen.infinitemovement.activity.MyCredentialActivity;
import com.runen.infinitemovement.activity.MyHozomActivity;
import com.runen.infinitemovement.activity.MyMedalActivity;
import com.runen.infinitemovement.activity.MyTheLongMarchRoadActivity;
import com.runen.infinitemovement.activity.WeTheLongMarchRoadActivity;
import com.runen.infinitemovement.activity.WebActivity;
import com.runen.infinitemovement.model.api.UserAPI;
import com.runen.infinitemovement.model.entity.ADDataEntity;
import com.runen.rxnetlibrary.utils.LogUtil;
import com.runen.rxnetlibrary.utils.SharePreferenceUtils;

/**
 * Create by LiaoDuanHong
 * Create on 2021/01/11 11:25
 */
public class ADToWebOrActivityUtil {
    public static void toType(Context context, ADDataEntity dataEntity) {
        if (dataEntity != null) {
            if (dataEntity.type != null) {
                if (dataEntity.type == 1) {
                    toAPP(context, dataEntity.linkUrl, dataEntity.remarks);
                } else if (dataEntity.type == 2) {
                    Intent intent = new Intent(context, WebActivity.class);
                    if (dataEntity.positionName.contains("红包")) {
                        String str = dataEntity.linkUrl + "?token=%s";
                        intent.putExtra("LINK_URL", String.format(str, UserAPI.getUserToken()));
                        LogUtil.e("LINK_URL", String.format(str, UserAPI.getUserToken()));
                    } else {
                        intent.putExtra("LINK_URL", dataEntity.linkUrl.trim());
                    }
                    context.startActivity(intent);
                }
            }
        }

    }

    /**
     * 跳转到app内部
     *
     * @param context
     * @param linkUrl
     */
    private static void toAPP(Context context, String linkUrl, String remarks) {
        switch (linkUrl) {
            case "1"://1.我们的长征路
                Intent intent = new Intent(context, MyTheLongMarchRoadActivity.class);
                intent.putExtra("userId", UserAPI.getUserId());
                context.startActivity(intent);
                break;
            case "2"://2.我的长征路
                Intent intent1 = new Intent(context, WeTheLongMarchRoadActivity.class);
                intent1.putExtra("companyId", SharePreferenceUtils.getString(context, "companyId"));
                context.startActivity(intent1);
                break;
            case "3"://3.开始跑步
                MainActivity.checkFragment(88);
                break;
            case "4"://4.开始健走
                MainActivity.checkFragment(88);
                break;
            case "5"://5.开始骑行
                MainActivity.checkFragment(88);
                break;
            case "6"://6.我的徽章
                Intent intent2 = new Intent(context, MyMedalActivity.class);
                context.startActivity(intent2);
                break;
            case "7"://7.我的火种
                context.startActivity(new Intent(context, MyHozomActivity.class));
                break;
            case "8"://8.每日任务
                context.startActivity(new Intent(context, DayTaskActivity.class));
                break;
            case "9"://9.我的证书
                context.startActivity(new Intent(context, MyCredentialActivity.class));
                break;
            case "10"://10.邀请好友
                context.startActivity(new Intent(context, InviteFriendsActivity.class));
                break;
            case "11"://11.兑换商店
                LogUtil.e("adAdapter", linkUrl);
                Intent shop = new Intent(context, WebActivity.class);
                shop.putExtra("LINK_URL", String.format(Constant.HOZOM_SHOP_H5, UserAPI.getUserToken()));
                context.startActivity(shop);
                break;
            case "12"://12.兑换步数进度
                break;
            case "13"://13.我的运动数据
                Intent inte = new Intent(context, WebActivity.class);
                String url = Constant.SPORTS_RECORD;
                inte.putExtra("LINK_URL", String.format(url, UserAPI.getUserToken()));
                context.startActivity(inte);
                break;
            case "14"://14.我的活动
                context.startActivity(new Intent(context, MyActivity.class));
                break;
            case "15"://15领取红包  //只是竞赛
//                Intent intentRed = new Intent(context, WebActivity.class);
//                String redUrl = Constant.RED_URL;
//                intentRed.putExtra("LINK_URL", String.format(redUrl, UserAPI.getUserToken()));
//                context.startActivity(intentRed);
                Intent intentRed = new Intent(context, WebActivity.class);
                String redUrl = Constant.H5_ASK_INDEX;
                intentRed.putExtra("LINK_URL", String.format(redUrl, UserAPI.getUserToken()));
                context.startActivity(intentRed);
                break;
            case "16":
                Intent intent4 = new Intent(context, WebActivity.class);
                String url4 = Constant.BASE_HOST_H5 + remarks + "?token=%s";
                intent4.putExtra("LINK_URL", String.format(url4, UserAPI.getUserToken()));
                context.startActivity(intent4);
                break;

        }
    }
}
